import { useCallback, useEffect, useState } from 'react';
import userSore, { useToLogin, useUserToken } from '@/store/userStore';
import { useRouter } from '../hooks';
import { CircleLoading } from '@/components/loading';
export default function AuthGuard({ children }) {
  const router = useRouter();
  const toLogin = useToLogin()
  const token = useUserToken();
  const [isLoginHint] = useState((userSore.getState().loginHintInfo.show))

  const check = useCallback(() => {
    if (!token) {
      // router.replace('/login');
      toLogin()
    }
  }, [router, token]);

  useEffect(() => {
    check();
  }, [check]);


  if (isLoginHint) {
    return <CircleLoading />
  }

  return children
}
